import 'package:flutter/material.dart';

class ConstantVariableDemoPage extends StatefulWidget{
  @override
  State<StatefulWidget> createState() => _ConstantVariableDemoState();

}

class _ConstantVariableDemoState extends State<ConstantVariableDemoPage>{

   @override
  void initState() {
    super.initState();
    print("====initState");
  }

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    print("====didChangeDependencies");
  }

  @override
  Widget build(BuildContext context) {
    print("====build");

    return Container(
      child: Column(
        children: [
          Text('测试生命周期'),
          TextButton(
              child: Text('点击切换'),
              onPressed: (){
            setState(() {
            });
          }),
          ChildWidget(),
        ],
      ),
    );
  }

   @override
   void deactivate() {
     super.deactivate();
     print("====deactivate");
   }

  @override
  void dispose() {
    super.dispose();
    print("====dispose");
  }
}

class ChildWidget extends StatefulWidget{
  @override
  State<StatefulWidget> createState() => _ChildWidgetState();
}

class _ChildWidgetState extends State<ChildWidget>{

  @override
  void initState() {
    super.initState();
    print("====child initState");
  }

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    print("====child didChangeDependencies");
  }

  @override
  Widget build(BuildContext context) {
    print("====child build");
    return Container(
      child: Column(
        children: [
          Text('子控件'),
          TextButton(
              child: Text('点击'),
              onPressed: (){
            setState(() {

            });
          })
        ],
      ),
    );
  }

  @override
  void deactivate() {
    super.deactivate();
    print("====child deactivate");
  }

  @override
  void dispose() {
    super.dispose();
    print("====child dispose");
  }

}

class ConstantVariableWidget extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    test();
    classType();
    return Scaffold(
      appBar: AppBar(
        title: Text('常量以及变量'),
      ),
      body: Align(
        child: Text('点击'),
      ),
    );
  }

  classType() {
    var a = 0;
    int b = 1;
    double c = 1.0;

    var s1 = 'cz';
    String s2 = "cz";

    var real = true;
    bool isReal = false;

    var arr = [1,2,3];

    List<int> arr2 = [1,2,3];
    // List<int> arr3 = List.filled(0, 0);
    var arr3 = [1, true, 'cz', 1.0];
    print(arr3);
    try{
      print(arr3.removeAt(5));
    }catch(e){
      print(e is RangeError);
      print(e);
    }
    // short long float double int String boolean
    // double int String boolean
    Map<String, String> map = new Map<String, String>();
    map['1'] = '1';
    map['name'] = 'cz';
    map['1'] = '2';
    map['2'] = '4';

    print(map);


    Text1 t = Text1();
    String name = t.text2.name;
    print("name${name != null ? name.isNotEmpty : " b"}");
  }

  test() {
    int a = 10;
    bool b = false;
    String name = 'cz';
    if(name is Characters){
      name.toString();
    }
    var name2 = "cz";
    dynamic name3 = "cz";
    print(""+a.toString()+" "+b.toString()+" "+name+" "+name2+" "+name3);

    final name4 = 'cz';
    final String name5 = "cz";

    final foo = [1,2];
    const baz = ['a','b',];
    print("    "+foo.toString()+" "+baz.toString());
  }
}

class Text1{
  String id = "";
  Text2 text2 = Text2();
}

class Text2 {
  String name = "";
}



